import { addPoleAPI, deletePoleAPI, fetchDropListAPI, fetchPoleListAPI, updatePoleAPI } from '@/api/rod/manageApi'

const actions = {
  /* 发送请求获取一体杆列表的action */
  async fetchPoleList(context, pageParams) {
    const { data } = await fetchPoleListAPI(pageParams)
    context.commit('updatePoleList', data)
  },
  /* 发送请求删除一体杆的action */
  async deletePole(context, id) {
    const { msg } = await deletePoleAPI(id)
    return msg
  },

  /* 发送请求添加一体杆的action */
  async addPole(context, formData) {
    const { msg } = await addPoleAPI(formData)
    return msg
  },

  /* 发送请求编辑一体杆的action */
  async updatePole(context, formData) {
    const { msg } = await updatePoleAPI(formData)
    return msg
  },
  /* 发送请求获取一体杆关联区域的列表的action */
  async fetchDropList(context) {
    const { data } = await fetchDropListAPI()
    context.commit('updateDropList', data)
  }
}
const mutations = {
  /* 更新一体杆列表的mutation */
  updatePoleList(state, poleListInfo) {
    state.poleListInfo = poleListInfo
  },
  /* 更新一体杆关联区域的mutation */
  updateDropList(state, propList) {
    state.propList = propList
  }
}
const state = () => {
  return {
    poleListInfo: {},
    propList: []
  }
}

const getters = {
  poleList(state) {
    return state.poleListInfo.rows
  },
  total(state) {
    return state.poleListInfo.total
  }
}

export default {
  actions,
  mutations,
  state,
  getters,
  namespaced: true
}
